<template>
  <div class="download">
    <div id="qrcode"></div>
    <div class="txt" v-if="type!='download'">我是{{name}}</div>
    <div class="fanhui" @click="goBack">
      <i class="iconfont icon-fanhui"></i>
      <span>返回</span>
    </div>
  </div>
</template>
<script>
import QRCode from "qrcodejs2";
import { mapGetters } from "vuex";
import { getGuid } from "../utils/index";
import { getUserInfo } from "../api.js";
import { Toast } from "mint-ui";

export default {
  name: "download",
  data() {
    return {
      name: "",
      type: this.$route.query.type
    };
  },
  components: { QRCode },
  computed: {
    ...mapGetters(["user"])
  },
  mounted() {
    this.getUserData();
  },
  methods: {
    qrcodeScan(EWMdress) {
      //生成二维码
      let qrcode = new QRCode("qrcode", {
        width: 116, // 二维码宽度
        height: 110, // 二维码高度
        text: EWMdress
      });
    },
    getUserData() {
      let id = localStorage.zyUserId;
      getUserInfo({
        ID: id,
        LoginMachine: getGuid()
      }).then(res => {
        if (res.data && res.data.Success) {
          console.log();
          this.name = res.data.EntityList[0].NickName;
          let { EWMdress } = res.data.EntityList[0];
          if (this.$route.query.type == "download") {
            EWMdress = "http://www.912cc.com";
          }
          this.qrcodeScan(EWMdress);
        } else {
          Toast({
            message: res.data.Content,
            duration: 3000
          });
        }
      });
    },
    goBack() {
      this.$router.go(-1);
    }
  }
};
</script>
<style lang="stylus" scoped>
.download {
  width: 100%;
  height: 13.34rem;
  background: url('../assets/imgBTC/download.png');
  background-size: 100% 100%;
  position: relative;

  #qrcode {
    position: absolute;
    top: 79%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .txt {
    position: absolute;
    top: 90.5%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #303030;
    font-size: 14px;
  }

  .fanhui {
    position: absolute;
    top: 0.3rem;
    left: 0.2rem;
    color: #ffffff;
    line-height: 20px;

    i {
      font-size: 22px;
    }

    span {
      font-size: 15px;
      position: relative;
      left: -5px;
      top: -3px;
    }
  }
}
</style>

